﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class User_passed : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["tid"] == null)
            Response.Redirect("../Error/Error.htm");
        if (!IsPostBack)
        {
            string depart = Session["depart"].ToString();
            bindDDL();
            createDDL();
            bindGridView();
            this.labKey1.Text = depart;
        }
    }
    //附件图片链接处理
    static public string strImage(string attach)
    {
        return (attach != string.Empty) ? "../Images/attachment-green.png" : "../Images/un-attachment.png";
    }
    //绑定DDL
    protected void bindDDL()
    {
        string sqlstr = "select btnname from Sys_Guide where btnstate<>'admin' order by id";
        PM.Code.Web.controlbind.BindDropDownList(this.ddlType, sqlstr, "btnname", "btnname");
        this.ddlType.Items.Insert(0, new ListItem("——全部——", "0"));
    }
    //生成DDL
    protected void createDDL()
    {
        int year = DateTime.Now.Year;
        for (int i = 0; i < 3; i++)
        {
            this.ddlYear.Items.Add((year - i).ToString());
        }
        this.ddlYear.Items.Insert(0, new ListItem("—全部—", "0"));
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView();
        if (this.ddlType.SelectedIndex != 0)
        {
            this.labkey3.Text = this.ddlType.SelectedValue.Trim();
        }
        else
            this.labkey3.Text = "";
    }
    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView();
        if (this.ddlYear.SelectedIndex != 0)
        {
            this.labkey4.Text = this.ddlYear.SelectedValue.Trim() + "年";
        }
        else
            this.labkey4.Text = "";
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bindGridView();
    }

    protected void bindGridView()
    {
        StringBuilder sqlstr = new StringBuilder("status=2 and pmanager='").Append(Session["tid"].ToString()).Append("'");
        strwhere(ref sqlstr);
        PM.Code.Web.controlbind.BindGridViewPublicProc(GridView1, AspNetPager1, "View_Projects", "id", "id,[type],pname,sub2,[name],attached,builddate", "id asc", sqlstr.ToString(), true);
    }

    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["tid"] == null)
            Response.Redirect("../Error/Error.htm");
        string tid = Session["tid"].ToString();
        StringBuilder sqlstr = new StringBuilder(" select [type] as 类型,pname as 项目名称,sub2 as 学科,[name] as 负责人,builddate as 建设时间 from View_Projects where status=2 and pmanager='").Append(tid).Append("'");
        strwhere(ref sqlstr);
        DataTable mytable = PM.Code.DAL.DbHelper.ExecuteDataTableBySql(sqlstr.ToString());
        PM.Code.Web.output.DataTableToExcel(mytable, "待终审项目汇总表");
    }

    protected void strwhere(ref StringBuilder sqlstr)
    {
        if (this.ddlType.SelectedValue != "0")
            sqlstr.Append(" and [type]='").Append(ddlType.SelectedValue.Trim()).Append("'");
        if (this.ddlYear.SelectedValue != "0")
            sqlstr.Append(" and year(builddate) = ").Append(ddlYear.SelectedValue.Trim());
    }
}
